﻿using System;
using UnityEngine;
using UnityEngine.UIElements;
using winS.UnityEditor.UIElement;
using TextField = winS.UnityEditor.UIElement.TextField;

namespace winS.UnityEditor.ProcessEditor
{
    public class Filter : VisualElement
    {
        public Action<string> onTextChanged;

        public Filter()
        {
            style.flexGrow = 1;
            style.flexDirection = FlexDirection.Row;

            TextField textField = EditorElementUtility.elementFactory.CreateTextField(newValue => onTextChanged?.Invoke(newValue));
            textField.style.flexGrow = 1;
            textField.textInput.style.paddingLeft = 20f;
            Add(textField);

            Icon filterIcon = EditorElementUtility.elementFactory.CreateIcon(Resources.Load<Texture>("winS.UnityEditor.ProcessEditor/Icons/放大镜"));
            filterIcon.style.alignSelf = Align.Center;
            filterIcon.style.position = Position.Absolute;
            filterIcon.style.left = 4f;
            Add(filterIcon);
        }
    }
}